package servlet;

import dao.Db;
import javabean.Worker;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/getOne")
public class UpdataData extends GenericServlet {
    @Override
    public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
        //设置编码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        //收参
        String id = req.getParameter("id");

        //通过数据查询，访问数据访问层
        Db db = new Db();
        Worker worker = db.getOneData(id);

        //渲染一个表单，用来放获取到的数据
        PrintWriter writer = resp.getWriter();
        writer.write("<!doctype html>");
        writer.write("<html>");
        writer.write("<head><title>员工信息更改</title><meta charset='utf-8'></head>");
        writer.write("<body style='background:lightpink;'>");
        writer.write("<form action='/JavaWebStudy_war_exploded/update'>");
        writer.write("ID<input type='text' value='"+worker.getId()+"' name='id'><br>");
        writer.write("姓名<input type='text' value='"+worker.getName()+"' name='name'><br>");
        writer.write("工作<input type='text' value='"+worker.getWork()+"' name='work'><br>");
        writer.write("<input type='submit' value='确认更新'><br>");
        writer.write("</form>");
        writer.write("</body>");
        writer.write("</html>");

    }
}
